<template>
  <!-- 新建党组织弹框 -->
  <el-dialog class="addplay_dialog"
  :visible.sync="visible"
  title="新建党组织"
  @close="cancel"
  :close-on-click-modal="false" 
  :close-on-press-escape="false"
  :append-to-body="true">
    <el-form :model="partyForm" label-width="125px">
        <el-form-item label="党组织名称：">
            <el-input class="inputBox" v-model="partyForm.name"></el-input>
        </el-form-item>
        <el-form-item label="所在院系：">
            <!-- <el-input v-model="partyForm.academyId"></el-input> -->
            <el-select v-model="partyForm.academyId" placeholder="请选择">
                <el-option 
                v-for="item in acadeList" 
                :key="item.id"
                :value="item.id"
                :label="item.academyName"
                >
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="创建时间：">
            <!-- <el-input v-model="partyForm.createTime"></el-input> -->
            <div class="block">
                <el-date-picker value-format="yyyy-MM-dd HH:mm:ss"
                    v-model="partyForm.createTime"
                    type="datetime"
                    placeholder="选择时间">
                </el-date-picker>
            </div>
        </el-form-item>
        <el-form-item label="上级党组织名称：">
            <!-- <el-input v-model="partyForm.parentId"></el-input> -->
            <el-select v-model="partyForm.parentId" clearable placeholder="选择党组织">
                  <el-option
                    v-for="item in patyList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="党组织级别：">
            <!-- <el-input class="inputBox" v-model="partyForm.grade" placeholder="一级党组织/二级党组织/三级党组织..."></el-input> -->
            <el-select v-model="partyForm.grade" clearable placeholder="党组织级别">
                  <el-option
                    v-for="item in levelList"
                    :key="item.id"
                    :label="item.value"
                    :value="item.value">
                  </el-option>
            </el-select>
        </el-form-item>
    </el-form>
    <div class="party_button">
        <el-button type="primary" @click="sure">确认</el-button>
        <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import axios from "axios"
export default {
    data(){
        return{
            visible: false,
            partyForm:{
                // name:"",//党组织名称
            },
            acadeList:[],//学院列表
            patyList:[],//党组织列表
            props: { multiple: true },
            levelList:[
                {
                    id:1,
                    value:"一级党组织",
                },{
                    id:2,
                    value:"二级党组织",
                },{
                    id:3,
                    value:"三级党组织",
                },
            ],//权限级别
        }
    },
    mounted(){
        this.acade()
        this.organizationList()
    },
    methods:{
        init (e) {
            // console.log(e)
            this.visible = true
            this.$nextTick(() => {
                // this.$refs['dataForm'].resetFields()
            })
        },
        acade(){//查询所有学院列表
            this.axios({
                headers:{'Authentication':localStorage.getItem('token')},
                method:"get",
                // url:"api/academy/getAcademyList",
                url:"/academy/getAcademyList",
                data:""
            }).then(res=>{
                if(res.data.code != 20001){
                    return this.$message.error(res.data.msg)
                }
                this.acadeList = res.data.data
                // console.log("添加成功")
            })
        },
        organizationList(){//党组织列表
            this.axios({
                headers:{'Authentication':localStorage.getItem('token')},
                // url:"api/organization/getOrganizationList",
                url:"/organization/getOrganizationList",
                method:"get",
            }).then(res=>{
                // console.log(res)
                if(res.data.code != 20001){
                return this.$message.error(res.data.msg)
                }
                else{
                    this.patyList = res.data.data
                    // console.log(this.patyList)
                    var heighplay = {
                        name:"无上级党组织",
                        id:-1
                    }
                    this.patyList.push(heighplay)
                }
            })
            },
        cancel(){//点击取消按钮
            this.visible = false
            this.partyForm={}
        },
        sure(){//点击确认按钮
        // console.log(this.partyForm)
            this.axios({
                headers:{'Authentication':localStorage.getItem('token')},
                method:"POST",
                // url:"api/organization/saveOrganization",
                url:"/organization/saveOrganization",
                data:this.partyForm
            }).then(res=>{
                if(res.data.code != 20001){
                    return this.$message.error(res.data.msg)
                }
                this.$alert('新建成功', {
                    confirmButtonText: '确定',
                    callback: action => {
                        this.visible = false
                        this.partyForm={}
                        this.$emit('Organization')
                    }
                });
            })
        }
    }
}
</script>

<style lang="scss">
.addplay_dialog{
    .el-dialog{
        height: 78vh;
    }
    .party_button{
        width: 100%;
        // border: 1px solid #000;
        text-align: center;
        position: absolute;
        bottom: 3vh;
        left: 0;
    }
    .inputBox{
        width: 300px;
    }
}
</style>